﻿ 
using System;
using System.IO;
using System.Xml;

namespace HBase {
    public class ConfUtil {
        static XmlDocument doc = null;
        static object obj = new object();
        public static string getStr( string key) {
            lock(obj)  {
                if (doc == null)
                {
                    String path = "Conf" + Path.DirectorySeparatorChar + "DataBase.config";
                    doc = new XmlDocument();
                    doc.Load(path);
                }
            }
           
            XmlElement root = doc.DocumentElement;
            XmlNodeList childNodes = root.ChildNodes;
            for (int i = 0; i < childNodes.Count; i++)
            {
                XmlNode node = childNodes[i];
                if (node.Name == key) {
                    var connStr1 = node.Attributes["connectionString"].Value;
                    if (String.IsNullOrEmpty(connStr1)) {
                        throw new Exception("配置异常" + key);
                    }
                    return connStr1;
                }
                 
            } 
            throw new Exception("配置节点异常" + key);

        }
        public static string getMongodb() {
            return getStr( "MongoDB");

        }

        public static string getDbName() {
            return getStr( "dbName");

        }
    }
}
